package exception;/**
 * @Auther: liyipeng
 * @Date: 2020/1/10 14:35
 * @Description:
 */

import org.springframework.util.StringUtils;
import responseModel.CodeDesc;
import responseModel.RspMessage;

import java.util.Map;

/**
 * <p>类名: BaseException</p>
 * <p>描述:TODO</p>
 * <p>创建人: liyp</p>
 * <p>创建时间: 2020/1/10 14:35</p>
 * <p>@version 2.0  </p>
 * <p>修改内容: ......</p>
 * <p>修改说明: ......</p>
 * <p>修改时间: ......</p>
 * <p>修改人: ......</p>
 * <p>每次修改，请增加上述修改信息说明</>
 */
public abstract class BaseException extends RuntimeException {

    public BaseException() {
    }

    public BaseException(Throwable ex) {
        super(ex);
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(String message, Throwable ex) {
        super(message, ex);
    }


    public void handler(RspMessage rsp, Map<String, CodeDesc> mapcode) {
        rsp.setCode(mapcode.get(getCodeDescFinal()).getCode());
        if (StringUtils.hasText(getMessage())) {
            rsp.setMessage(getMessage());
        }
        else {
            rsp.setMessage(mapcode.get(getCodeDescFinal()).getMessage());
        }

    }

    protected abstract  String getCodeDescFinal();

}
